# -*- encoding: utf-8 -*-

class Cmp (object):

    """ Classe définissant une instruction CMP Ra, Rb """

    def __init__ (self, ra, rb, mem):
        self.__ra = ra
        self.__rb = rb
        self.__mem = mem

    def do (self):
        res = self.__mem.getRegister(self.__ra) - self.__mem.getRegister(self.__rb)
        self.__mem.setFlag('Z', res == 0)
        self.__mem.setFlag('O', res >= 128 or res < -128)
        self.__mem.setFlag('N', res < 0)
        self.__mem.setFlag('C', (res/256)%2) # Euh... Pas sûr que ça marche ça...


    def __str__ (self):
        return "cmp r{0:d} r{1:d}".format(self.__ra, self.__rb) 

    def __unicode__ (self):
        return self.__str__ () 
